#!/bin/sh
# The ARP Scanner (arp-scan) is Copyright (C) 2005-2016 Roy Hills,
# NTA Monitor Ltd.
#
# This file is part of arp-scan.
#
# arp-scan is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# arp-scan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with arp-scan.  If not, see <http://www.gnu.org/licenses/>.
#
# check-host-list - Shell script to test arp-scan host list creation
#
# Author: Roy Hills
# Date: 4 February 2011
#
# This script checks that arp-scan creates the host list correctly.
# It uses the undocumented arp-scan option --readpktfromfile to
# read the packets from a pcap file rather than from the network.
#

ARPSCANOUTPUT=/tmp/arp-scan-output.$$.tmp
EXAMPLEOUTPUT=/tmp/example-output.$$.tmp
#
SAMPLE01="$srcdir/pkt-net1921681-response.pcap"

# 56 ARP responses from a Class-C sized network with various vendors
echo "Checking host list creation using $SAMPLE01 ..."
cat >$EXAMPLEOUTPUT <<_EOF_
Host List:

Entry	IP Address
1	192.168.1.0
2	192.168.1.1
3	192.168.1.2
4	192.168.1.3
5	192.168.1.4
6	192.168.1.5
7	192.168.1.6
8	192.168.1.7
9	192.168.1.8
10	192.168.1.9
11	192.168.1.10
12	192.168.1.11
13	192.168.1.12
14	192.168.1.13
15	192.168.1.14
16	192.168.1.15
17	192.168.1.16
18	192.168.1.17
19	192.168.1.18
20	192.168.1.19
21	192.168.1.20
22	192.168.1.21
23	192.168.1.22
24	192.168.1.23
25	192.168.1.24
26	192.168.1.25
27	192.168.1.26
28	192.168.1.27
29	192.168.1.28
30	192.168.1.29
31	192.168.1.30
32	192.168.1.31
33	192.168.1.32
34	192.168.1.33
35	192.168.1.34
36	192.168.1.35
37	192.168.1.36
38	192.168.1.37
39	192.168.1.38
40	192.168.1.39
41	192.168.1.40
42	192.168.1.41
43	192.168.1.42
44	192.168.1.43
45	192.168.1.44
46	192.168.1.45
47	192.168.1.46
48	192.168.1.47
49	192.168.1.48
50	192.168.1.49
51	192.168.1.50
52	192.168.1.51
53	192.168.1.52
54	192.168.1.53
55	192.168.1.54
56	192.168.1.55
57	192.168.1.56
58	192.168.1.57
59	192.168.1.58
60	192.168.1.59
61	192.168.1.60
62	192.168.1.61
63	192.168.1.62
64	192.168.1.63
65	192.168.1.64
66	192.168.1.65
67	192.168.1.66
68	192.168.1.67
69	192.168.1.68
70	192.168.1.69
71	192.168.1.70
72	192.168.1.71
73	192.168.1.72
74	192.168.1.73
75	192.168.1.74
76	192.168.1.75
77	192.168.1.76
78	192.168.1.77
79	192.168.1.78
80	192.168.1.79
81	192.168.1.80
82	192.168.1.81
83	192.168.1.82
84	192.168.1.83
85	192.168.1.84
86	192.168.1.85
87	192.168.1.86
88	192.168.1.87
89	192.168.1.88
90	192.168.1.89
91	192.168.1.90
92	192.168.1.91
93	192.168.1.92
94	192.168.1.93
95	192.168.1.94
96	192.168.1.95
97	192.168.1.96
98	192.168.1.97
99	192.168.1.98
100	192.168.1.99
101	192.168.1.100
102	192.168.1.101
103	192.168.1.102
104	192.168.1.103
105	192.168.1.104
106	192.168.1.105
107	192.168.1.106
108	192.168.1.107
109	192.168.1.108
110	192.168.1.109
111	192.168.1.110
112	192.168.1.111
113	192.168.1.112
114	192.168.1.113
115	192.168.1.114
116	192.168.1.115
117	192.168.1.116
118	192.168.1.117
119	192.168.1.118
120	192.168.1.119
121	192.168.1.120
122	192.168.1.121
123	192.168.1.122
124	192.168.1.123
125	192.168.1.124
126	192.168.1.125
127	192.168.1.126
128	192.168.1.127
129	192.168.1.128
130	192.168.1.129
131	192.168.1.130
132	192.168.1.131
133	192.168.1.132
134	192.168.1.133
135	192.168.1.134
136	192.168.1.135
137	192.168.1.136
138	192.168.1.137
139	192.168.1.138
140	192.168.1.139
141	192.168.1.140
142	192.168.1.141
143	192.168.1.142
144	192.168.1.143
145	192.168.1.144
146	192.168.1.145
147	192.168.1.146
148	192.168.1.147
149	192.168.1.148
150	192.168.1.149
151	192.168.1.150
152	192.168.1.151
153	192.168.1.152
154	192.168.1.153
155	192.168.1.154
156	192.168.1.155
157	192.168.1.156
158	192.168.1.157
159	192.168.1.158
160	192.168.1.159
161	192.168.1.160
162	192.168.1.161
163	192.168.1.162
164	192.168.1.163
165	192.168.1.164
166	192.168.1.165
167	192.168.1.166
168	192.168.1.167
169	192.168.1.168
170	192.168.1.169
171	192.168.1.170
172	192.168.1.171
173	192.168.1.172
174	192.168.1.173
175	192.168.1.174
176	192.168.1.175
177	192.168.1.176
178	192.168.1.177
179	192.168.1.178
180	192.168.1.179
181	192.168.1.180
182	192.168.1.181
183	192.168.1.182
184	192.168.1.183
185	192.168.1.184
186	192.168.1.185
187	192.168.1.186
188	192.168.1.187
189	192.168.1.188
190	192.168.1.189
191	192.168.1.190
192	192.168.1.191
193	192.168.1.192
194	192.168.1.193
195	192.168.1.194
196	192.168.1.195
197	192.168.1.196
198	192.168.1.197
199	192.168.1.198
200	192.168.1.199
201	192.168.1.200
202	192.168.1.201
203	192.168.1.202
204	192.168.1.203
205	192.168.1.204
206	192.168.1.205
207	192.168.1.206
208	192.168.1.207
209	192.168.1.208
210	192.168.1.209
211	192.168.1.210
212	192.168.1.211
213	192.168.1.212
214	192.168.1.213
215	192.168.1.214
216	192.168.1.215
217	192.168.1.216
218	192.168.1.217
219	192.168.1.218
220	192.168.1.219
221	192.168.1.220
222	192.168.1.221
223	192.168.1.222
224	192.168.1.223
225	192.168.1.224
226	192.168.1.225
227	192.168.1.226
228	192.168.1.227
229	192.168.1.228
230	192.168.1.229
231	192.168.1.230
232	192.168.1.231
233	192.168.1.232
234	192.168.1.233
235	192.168.1.234
236	192.168.1.235
237	192.168.1.236
238	192.168.1.237
239	192.168.1.238
240	192.168.1.239
241	192.168.1.240
242	192.168.1.241
243	192.168.1.242
244	192.168.1.243
245	192.168.1.244
246	192.168.1.245
247	192.168.1.246
248	192.168.1.247
249	192.168.1.248
250	192.168.1.249
251	192.168.1.250
252	192.168.1.251
253	192.168.1.252
254	192.168.1.253
255	192.168.1.254
256	192.168.1.255

Total of 256 host entries.
_EOF_
ARPARGS="--retry=1 --ouifile=$srcdir/ieee-oui.txt --iabfile=$srcdir/ieee-iab.txt --macfile=$srcdir/mac-vendor.txt -v -v -v"
$srcdir/arp-scan $ARPARGS --readpktfromfile=$SAMPLE01 192.168.1.0/24 2>&1 | sed -n -e '/^Host List:/,/^Total of /p' > $ARPSCANOUTPUT 2>&1
if test $? -ne 0; then
   rm -f $ARPSCANOUTPUT
   rm -f $EXAMPLEOUTPUT
   echo "FAILED"
   exit 1
fi
cmp -s $ARPSCANOUTPUT $EXAMPLEOUTPUT
if test $? -ne 0; then
   rm -f $ARPSCANOUTPUT
   rm -f $EXAMPLEOUTPUT
   echo "FAILED"
   exit 1
fi
echo "ok"
rm -f $ARPSCANOUTPUT
rm -f $EXAMPLEOUTPUT
#
echo "Checking random host list creation using $SAMPLE01 ..."
cat >$EXAMPLEOUTPUT <<_EOF_
Host List:

Entry	IP Address
1	192.168.1.149
2	192.168.1.211
3	192.168.1.122
4	192.168.1.254
5	192.168.1.45
6	192.168.1.15
7	192.168.1.226
8	192.168.1.84
9	192.168.1.47
10	192.168.1.80
11	192.168.1.113
12	192.168.1.247
13	192.168.1.118
14	192.168.1.191
15	192.168.1.196
16	192.168.1.210
17	192.168.1.206
18	192.168.1.184
19	192.168.1.245
20	192.168.1.237
21	192.168.1.2
22	192.168.1.240
23	192.168.1.63
24	192.168.1.153
25	192.168.1.223
26	192.168.1.4
27	192.168.1.133
28	192.168.1.16
29	192.168.1.58
30	192.168.1.103
31	192.168.1.169
32	192.168.1.179
33	192.168.1.19
34	192.168.1.37
35	192.168.1.64
36	192.168.1.44
37	192.168.1.151
38	192.168.1.163
39	192.168.1.111
40	192.168.1.93
41	192.168.1.152
42	192.168.1.203
43	192.168.1.14
44	192.168.1.67
45	192.168.1.135
46	192.168.1.215
47	192.168.1.38
48	192.168.1.86
49	192.168.1.52
50	192.168.1.74
51	192.168.1.218
52	192.168.1.65
53	192.168.1.30
54	192.168.1.197
55	192.168.1.134
56	192.168.1.147
57	192.168.1.123
58	192.168.1.174
59	192.168.1.126
60	192.168.1.6
61	192.168.1.143
62	192.168.1.144
63	192.168.1.251
64	192.168.1.241
65	192.168.1.168
66	192.168.1.159
67	192.168.1.120
68	192.168.1.109
69	192.168.1.204
70	192.168.1.39
71	192.168.1.35
72	192.168.1.177
73	192.168.1.157
74	192.168.1.231
75	192.168.1.234
76	192.168.1.239
77	192.168.1.25
78	192.168.1.171
79	192.168.1.51
80	192.168.1.187
81	192.168.1.72
82	192.168.1.69
83	192.168.1.232
84	192.168.1.181
85	192.168.1.150
86	192.168.1.100
87	192.168.1.24
88	192.168.1.1
89	192.168.1.130
90	192.168.1.33
91	192.168.1.136
92	192.168.1.50
93	192.168.1.175
94	192.168.1.95
95	192.168.1.131
96	192.168.1.61
97	192.168.1.209
98	192.168.1.249
99	192.168.1.236
100	192.168.1.225
101	192.168.1.139
102	192.168.1.18
103	192.168.1.49
104	192.168.1.208
105	192.168.1.119
106	192.168.1.92
107	192.168.1.190
108	192.168.1.161
109	192.168.1.201
110	192.168.1.183
111	192.168.1.216
112	192.168.1.248
113	192.168.1.162
114	192.168.1.219
115	192.168.1.17
116	192.168.1.10
117	192.168.1.62
118	192.168.1.3
119	192.168.1.224
120	192.168.1.182
121	192.168.1.242
122	192.168.1.138
123	192.168.1.217
124	192.168.1.90
125	192.168.1.40
126	192.168.1.22
127	192.168.1.48
128	192.168.1.102
129	192.168.1.73
130	192.168.1.76
131	192.168.1.202
132	192.168.1.255
133	192.168.1.97
134	192.168.1.88
135	192.168.1.9
136	192.168.1.243
137	192.168.1.165
138	192.168.1.105
139	192.168.1.132
140	192.168.1.205
141	192.168.1.176
142	192.168.1.253
143	192.168.1.194
144	192.168.1.229
145	192.168.1.79
146	192.168.1.230
147	192.168.1.98
148	192.168.1.173
149	192.168.1.55
150	192.168.1.222
151	192.168.1.101
152	192.168.1.99
153	192.168.1.207
154	192.168.1.212
155	192.168.1.166
156	192.168.1.154
157	192.168.1.78
158	192.168.1.5
159	192.168.1.42
160	192.168.1.13
161	192.168.1.91
162	192.168.1.23
163	192.168.1.193
164	192.168.1.7
165	192.168.1.66
166	192.168.1.124
167	192.168.1.114
168	192.168.1.41
169	192.168.1.28
170	192.168.1.0
171	192.168.1.235
172	192.168.1.146
173	192.168.1.238
174	192.168.1.178
175	192.168.1.71
176	192.168.1.60
177	192.168.1.117
178	192.168.1.12
179	192.168.1.57
180	192.168.1.192
181	192.168.1.29
182	192.168.1.164
183	192.168.1.116
184	192.168.1.121
185	192.168.1.167
186	192.168.1.125
187	192.168.1.32
188	192.168.1.228
189	192.168.1.59
190	192.168.1.85
191	192.168.1.20
192	192.168.1.110
193	192.168.1.156
194	192.168.1.200
195	192.168.1.77
196	192.168.1.233
197	192.168.1.106
198	192.168.1.8
199	192.168.1.148
200	192.168.1.11
201	192.168.1.82
202	192.168.1.213
203	192.168.1.81
204	192.168.1.75
205	192.168.1.246
206	192.168.1.188
207	192.168.1.107
208	192.168.1.172
209	192.168.1.214
210	192.168.1.94
211	192.168.1.140
212	192.168.1.26
213	192.168.1.127
214	192.168.1.115
215	192.168.1.87
216	192.168.1.199
217	192.168.1.36
218	192.168.1.250
219	192.168.1.189
220	192.168.1.129
221	192.168.1.170
222	192.168.1.180
223	192.168.1.27
224	192.168.1.128
225	192.168.1.112
226	192.168.1.46
227	192.168.1.186
228	192.168.1.21
229	192.168.1.68
230	192.168.1.53
231	192.168.1.70
232	192.168.1.221
233	192.168.1.160
234	192.168.1.83
235	192.168.1.198
236	192.168.1.252
237	192.168.1.31
238	192.168.1.145
239	192.168.1.244
240	192.168.1.142
241	192.168.1.220
242	192.168.1.155
243	192.168.1.89
244	192.168.1.43
245	192.168.1.141
246	192.168.1.137
247	192.168.1.104
248	192.168.1.185
249	192.168.1.96
250	192.168.1.54
251	192.168.1.34
252	192.168.1.158
253	192.168.1.108
254	192.168.1.195
255	192.168.1.227
256	192.168.1.56

Total of 256 host entries.
_EOF_
ARPARGS="--retry=1 --ouifile=$srcdir/ieee-oui.txt --iabfile=$srcdir/ieee-iab.txt --macfile=$srcdir/mac-vendor.txt -v -v -v --random --randomseed=0xdeadbeef"
$srcdir/arp-scan $ARPARGS --readpktfromfile=$SAMPLE01 192.168.1.0/24 2>&1 | sed -n -e '/^Host List:/,/^Total of /p' > $ARPSCANOUTPUT 2>&1
if test $? -ne 0; then
   rm -f $ARPSCANOUTPUT
   rm -f $EXAMPLEOUTPUT
   echo "FAILED"
   exit 1
fi
cmp -s $ARPSCANOUTPUT $EXAMPLEOUTPUT
if test $? -ne 0; then
   rm -f $ARPSCANOUTPUT
   rm -f $EXAMPLEOUTPUT
   echo "FAILED"
   exit 1
fi
echo "ok"
rm -f $ARPSCANOUTPUT
rm -f $EXAMPLEOUTPUT
